package com.x.erp.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.erp.dao.ManufacturerDao;
import com.x.erp.model.Manufacturer;
import com.x.erp.model.Relation;
import com.x.erp.rpc.ManufacturerRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
@Service(interfaceName = "com.x.erp.rpc.ManufacturerRpcService", timeout = 60000)
public class ManufacturerService implements ManufacturerRpcService {
	@Autowired
	private ManufacturerDao manufacturerDao;

	@Override
	public List<Manufacturer> selectManufacturer(Manufacturer manufacturer) {
		try {
			return manufacturerDao.selectManufacturer(manufacturer);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0015, e);
		}
	}

    @Override
    public void insertManufacturerList(Manufacturer manufacturer) {
        try {
            manufacturerDao.insertManufacturerList(manufacturer);
//            manufacturerDao.delBrandManufacturer(manufacturer.getBrandId(), manufacturer.getManufacturerId());
//            manufacturerDao.insertBrandManufacturer(manufacturer.getBrandId(), manufacturer.getManufacturerId());
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0001, e);
        }
    }

    @Override
    public void updateManufacturerList(Manufacturer manufacturer) {
        try {
            manufacturerDao.updateManufacturerList(manufacturer);
//            manufacturerDao.delBrandManufacturer(manufacturer.getBrandId(), manufacturer.getManufacturerId());
//            manufacturerDao.insertBrandManufacturer(manufacturer.getBrandId(), manufacturer.getManufacturerId());
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0001, e);
        }
    }

    @Override
    public void delBrandManufacturer(Integer brandId, Integer manufacturerId) {
        try {
            manufacturerDao.delBrandManufacturer(brandId, manufacturerId);
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0001, e);
        }
    }

    @Override
    public void insertBrandManufacturer(Integer brandId, Integer manufacturerId) {
        try {
            manufacturerDao.insertBrandManufacturer(brandId, manufacturerId);
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0001, e);
        }
    }

    @Override
    public Manufacturer getSimpleManufacturer(Map<String, Object> manufacturer) {
        try {
            return manufacturerDao.getSimpleManufacturer(manufacturer);
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0001, e);
        }
    }

    @Override
    public List<Relation> getRelationList(Map<String, Object> relation) {
        try {
            return manufacturerDao.getRelationList(relation);
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0001, e);
        }
    }
}
